﻿Imports System.Text
Imports System.Threading
Imports System.IO.Pipes
Imports System.IO
Imports System.Runtime.InteropServices
Imports Windows7.DesktopIntegration
Imports Windows7.DesktopIntegration.WindowsForms
Imports System.Reflection
Imports NLocalizer
Imports System.Windows.Forms.Integration

Public Class Mainform
    Private currentPlaylist As Int64
    Dim isFullscreen As Boolean = False
    Dim isTopmost As Boolean = False
    Dim hasBorder As Boolean = True
    Dim testOnBorder As onBorder
    Dim tbm As ThumbButtonManager
    Dim WithEvents TrackBar1 As New ToolStripTrackBar2
    Dim WithEvents TrackBar2 As New ToolStripTrackBar2
    Public WithEvents TimerStop As New StopPC
    Dim PlayRecord As Boolean = False
    Dim Language As String
    Dim ChaineActuelle As String = ""
    Dim IsRadio As Boolean = False
#Region "Gestion de la souris"

#Region "Constantes"
    Private Const WM_NCLBUTTONDOWN As Integer = &HA1
    Private Const HTBORDER As Integer = 18
    Private Const HTBOTTOM As Integer = 15
    Private Const HTBOTTOMLEFT As Integer = 16
    Private Const HTBOTTOMRIGHT As Integer = 17
    Private Const HTCAPTION As Integer = 2
    Private Const HTLEFT As Integer = 10
    Private Const HTRIGHT As Integer = 11
    Private Const HTTOP As Integer = 12
    Private Const HTTOPLEFT As Integer = 13
    Private Const HTTOPRIGHT As Integer = 14
#End Region

    <DllImport("user32.dll")> _
    Public Shared Function ReleaseCapture() As Boolean
    End Function

    <DllImport("user32.dll")> _
    Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
    End Function


    Private Sub Mainform_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If Not hasBorder Then
            testOnBorder = inPanelBorder(e.Location)
            Select Case testOnBorder
                Case onBorder.None
                    Me.Cursor = Cursors.Arrow
                Case onBorder.Top
                    Me.Cursor = Cursors.SizeNS
                Case onBorder.Right
                    Me.Cursor = Cursors.SizeWE
                Case onBorder.TopRight
                    Me.Cursor = Cursors.SizeNESW
                Case onBorder.RightBottom
                    Me.Cursor = Cursors.SizeNWSE
                Case onBorder.Bottom
                    Me.Cursor = Cursors.SizeNS
                Case onBorder.BottomLeft
                    Me.Cursor = Cursors.SizeNESW
                Case onBorder.Left
                    Me.Cursor = Cursors.SizeWE
                Case onBorder.LeftTop
                    Me.Cursor = Cursors.SizeNWSE
            End Select

        End If
    End Sub

    Private Sub Mainform_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        If Not (Control.ModifierKeys And Keys.Control) = Keys.Control Then
            If Not hasBorder Then
                Dim dir As Integer = -1
                Select Case testOnBorder
                    Case onBorder.Top
                        dir = HTTOP
                    Case onBorder.TopRight
                        dir = HTTOPRIGHT
                    Case onBorder.Right
                        dir = HTRIGHT
                    Case onBorder.RightBottom
                        dir = HTBOTTOMRIGHT
                    Case onBorder.Bottom
                        dir = HTBOTTOM
                    Case onBorder.BottomLeft
                        dir = HTBOTTOMLEFT
                    Case onBorder.Left
                        dir = HTLEFT
                    Case onBorder.LeftTop
                        dir = HTTOPLEFT
                End Select
                If dir <> -1 Then
                    ReleaseCapture()
                    SendMessage(Me.Handle, WM_NCLBUTTONDOWN, dir, 0)
                End If

            End If

        Else
            ReleaseCapture()
            SendMessage(Me.Handle, WM_NCLBUTTONDOWN, HTCAPTION, 0)

        End If

    End Sub

    Private Sub Mainform_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseWheel
        If (Control.ModifierKeys And Keys.Control) <> Keys.Control Then
            If e.Delta > 0 Then
                VolumePlus()
                TestVolume()
                TrackBar1.Value = Volume
                TrackBar2.Value = Volume
            ElseIf e.Delta < 0 Then
                VolumeMoins()
                TestVolume()
                TrackBar1.Value = Volume
                TrackBar2.Value = Volume
            End If
        Else
            If Not PlayRecord Then
                Dim infoChaine As String() = {}
                If e.Delta > 0 Then
                    infoChaine = ChannelPlus()
                ElseIf e.Delta < 0 Then
                    infoChaine = ChannelMoins()
                End If
                If Not (infoChaine(1).Equals("")) AndAlso Not (infoChaine(0).Equals("")) Then
                    AfficheOSDChaine(_Aller & infoChaine(1) & " - " & infoChaine(0))
                    buffChaine.Clear()
                    buffChaine.Append(infoChaine(1))
                    timBuffChaine.Enabled = True
                    timBuffChaine.Stop()
                    timBuffChaine.Start()
                End If
            End If
        End If
    End Sub

    Private Function inPanelBorder(ByVal pos As Point) As onBorder
        Dim pointMe As New Point
        pointMe = New Point(0, 0)
        Dim RetourOnborder As onBorder = onBorder.None
        If pos.Y < pointMe.Y + 8 Then RetourOnborder = RetourOnborder Or onBorder.Top
        If pos.Y > pointMe.Y + Me.Height - 8 Then RetourOnborder = RetourOnborder Or onBorder.Bottom
        If pos.X < pointMe.X + 8 Then RetourOnborder = RetourOnborder Or onBorder.Left
        If pos.X > pointMe.X + Me.Width - 8 Then RetourOnborder = RetourOnborder Or onBorder.Right
        Return RetourOnborder
    End Function

    Private Enum onBorder
        None = 0
        Top = 1
        Right = 2
        Bottom = 4
        Left = 8
        TopRight = 3
        RightBottom = 6
        LeftTop = 9
        BottomLeft = 12
    End Enum

    Private Sub pnlVideo_MouseDoubleClick(ByVal Sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlVideo.MouseDoubleClick
        CacherSousMenu()
        ToggleFullscreen()
    End Sub
    Private Sub CacherSousMenu()
        For Each TSMI As Object In mnsMainform.Items
            If TypeOf (TSMI) Is ToolStripMenuItem Then
                CType(TSMI, ToolStripMenuItem).HideDropDown()
            End If
        Next

    End Sub

    Private Sub pnlVideo_MouseDown(ByVal Sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pnlVideo.MouseDown
        CacherSousMenu()
        Select Case e.Button
            Case MouseButtons.Left
                If ContextMenuStripPnlVideo.Visible Then
                    ContextMenuStripPnlVideo.Hide()
                Else
                    ToggleBorder()
                End If

            Case MouseButtons.Middle
                If ContextMenuStripPnlVideo.Visible Then
                    ContextMenuStripPnlVideo.Hide()
                Else
                    AfficheOSDChaine()
                End If
            Case MouseButtons.Right
                ContextMenuStripPnlVideo.Show(Cursor.Position)
        End Select

    End Sub

#End Region

#Region "Gestion du clavier"

    <DllImport("user32.dll")>
    Public Shared Function RegisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer, ByVal fsModifier As Integer, ByVal vlc As Integer) As Boolean
    End Function

    <DllImport("user32.dll")>
    Public Shared Function UnregisterHotKey(ByVal hWnd As IntPtr, ByVal id As Integer) As Boolean
    End Function

    'Public Const ALT As Integer = 1
    'Public Const CTRL As Integer = 2
    'Public Const SHIFT As Integer = 4
    'Public Const WIN As Integer = 8
    Public Const HK_MSG_ID As Integer = &H312

    Public Sub initHotKey()
        RegisterHotKey(Me.Handle, 100, 0, Keys.VolumeDown)
        RegisterHotKey(Me.Handle, 200, 0, Keys.VolumeUp)
        RegisterHotKey(Me.Handle, 300, 0, Keys.VolumeMute)

        'RegisterHotKey(Me.Handle, 400, 0, Keys.PrintScreen) 'Ne marche pas s'il y a un utilitaire de capture
    End Sub

    Public Sub releaseHotkey()
        UnregisterHotKey(Me.Handle, 100)
        UnregisterHotKey(Me.Handle, 200)
        UnregisterHotKey(Me.Handle, 300)
        'UnregisterHotKey(Me.Handle, 400)
    End Sub

    Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Activated
        initHotKey()
    End Sub

    Private Sub Form1_Deactivate(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Deactivate
        releaseHotkey()
    End Sub

    Private WithEvents timBuffChaine As New System.Windows.Forms.Timer
    Private buffChaine As New StringBuilder

    Private Sub timbuffChaineTick(ByVal myObject As Object, ByVal myEventArgs As EventArgs) Handles timBuffChaine.Tick
        timBuffChaine.Stop()
        If buffChaine.Length > 0 AndAlso Integer.Parse(buffChaine.ToString) > 0 AndAlso Integer.Parse(buffChaine.ToString) <= ChannelCount Then
            If ChooseChannelByOrdering(Integer.Parse(buffChaine.ToString)) Then
                Watch()
            End If
            MajChainesToolStrip()
        End If

        buffChaine.Clear()
    End Sub

    Private Sub Mainform_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        Dim keyt As Keys = e.KeyCode

        Select Case keyt
            Case Keys.S
                Snapshot(SnapshotsPath & "Snapshot_" & DateTime.Now.Year & DateTime.Now.Month & DateTime.Now.Day & DateTime.Now.Hour & DateTime.Now.Minute & DateTime.Now.Second & ".png")
            Case Keys.C
                ToggleCompensatePalSpeedUp()
                PALFILMToolStripMenuItem.Checked = CompensationPalSpeedUp
                PALFilmToolStripMenuItem1.Checked = CompensationPalSpeedUp
            Case Keys.I
                AfficheOSDChaine()
            Case Keys.X
                Me.Close()
            Case Keys.Left, Keys.VolumeDown

                VolumeMoins()
                TestVolume()
                TrackBar1.Value = Volume
                TrackBar2.Value = Volume
                buffChaine.Clear()
                timBuffChaine.Enabled = False

            Case Keys.Right, Keys.VolumeUp
                VolumePlus()
                TestVolume()
                TrackBar1.Value = Volume
                TrackBar2.Value = Volume
                buffChaine.Clear()
                timBuffChaine.Enabled = False


            Case Keys.Up, Keys.MediaNextTrack
                If Not PlayRecord Then

                    ChooseChannelPlus()
                    MajChainesToolStrip()
                    buffChaine.Clear()
                    timBuffChaine.Enabled = False
                End If
            Case Keys.Down, Keys.MediaPreviousTrack
                If Not PlayRecord Then
                    ChooseChannelMoins()
                    MajChainesToolStrip()
                    buffChaine.Clear()
                    timBuffChaine.Enabled = False
                End If
            Case Keys.Z
                If ToggleChannel() Then
                    Watch()
                    MajChainesToolStrip()
                End If
            Case Keys.M, Keys.VolumeMute
                ToggleMute()
                TestVolume()
                TrackBar1.Value = Volume
                TrackBar2.Value = Volume
                buffChaine.Clear()
                timBuffChaine.Enabled = False
            Case Keys.MediaPlayPause, Keys.P
                If isPlaying Then
                    Pause()
                    PlayPauseToolStripMenuItem.Image = My.Resources.control
                Else
                    Play()
                    PlayPauseToolStripMenuItem.Image = My.Resources.controlpause
                End If
                VisuRateToolStripMenuItem.Text = Speed
                buffChaine.Clear()
                timBuffChaine.Enabled = False
            Case Keys.R
                If isPlaying Then
                    FileName = VideosPath & "Chaine" & DateTime.Now.Year & "_" & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" & DateTime.Now.Hour & "H" & DateTime.Now.Minute & DateTime.Now.Second & ".ts"
                    RecordNow = Not (RecordNow)
                    If RecordNow Then
                        RecordToolStripMenuItem.Image = My.Resources.controlpauserecord
                        EnregistrerToolStripMenuItem.Text = _Arreter
                        EnregistrerToolStripMenuItem1.Text = _Arreter

                    Else
                        RecordToolStripMenuItem.Image = My.Resources.controlrecord
                        EnregistrerToolStripMenuItem.Text = _enregistrer
                        EnregistrerToolStripMenuItem1.Text = _enregistrer

                    End If
                End If
            Case Keys.Enter
                ToggleFullscreen()
            Case Keys.B
                ToggleBorder()
            Case Keys.NumPad0, Keys.NumPad1, Keys.NumPad2, Keys.NumPad3, _
                Keys.NumPad4, Keys.NumPad5, Keys.NumPad6, Keys.NumPad7, _
                Keys.NumPad8, Keys.NumPad9, Keys.D0, Keys.D1, Keys.D2, Keys.D3, _
                Keys.D4, Keys.D5, Keys.D6, Keys.D7, Keys.D8, Keys.D9
                If Not PlayRecord Then
                    Dim tmpchar As String
                    Select Case keyt
                        Case Keys.D0
                            tmpchar = "0"
                        Case Keys.D1
                            tmpchar = "1"
                        Case Keys.D2
                            tmpchar = "2"
                        Case Keys.D3
                            tmpchar = "3"
                        Case Keys.D4
                            tmpchar = "4"
                        Case Keys.D5
                            tmpchar = "5"
                        Case Keys.D6
                            tmpchar = "6"
                        Case Keys.D7
                            tmpchar = "7"
                        Case Keys.D8
                            tmpchar = "8"
                        Case Keys.D9
                            tmpchar = "9"
                        Case Else
                            tmpchar = GetCharFromKey(e.KeyCode, 0)
                    End Select

                    buffChaine.Append(tmpchar)

                    If buffChaine.Length > 3 Then
                        buffChaine.Remove(0, 1)
                    End If
                    AfficheOSDChaine(_Aller & buffChaine.ToString & " - " & ChannelNameByOrdering(CInt(buffChaine.ToString)))
                    timBuffChaine.Enabled = True
                    timBuffChaine.Stop()
                    timBuffChaine.Start()
                End If
        End Select

    End Sub

    Public Function GetCharFromKey(ByVal KeyCode As Integer, ByVal Scancode As Integer) As String
        Dim inBuffer(2) As Byte
        Dim keyState(256) As Byte
        GetKeyboardState(keyState)

        If ToAscii(KeyCode, Scancode, keyState, inBuffer, 0) > 0 Then
            Return BitConverter.ToChar(inBuffer, 0)
        Else
            Return ""
        End If

    End Function

    <DllImport("user32")> _
    Public Shared Function ToAscii( _
        ByVal uVirtKey As Integer, _
        ByVal uScanCode As Integer, _
        ByVal lpbKeyState() As Byte, _
        ByVal lpwTransKey() As Byte, _
        ByVal fuState As Integer) As Integer
    End Function

    <DllImport("user32")> _
    Public Shared Function GetKeyboardState(ByVal pbKeyState() As Byte) As Integer
    End Function

#End Region

#Region "Taskbar"

    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = Windows7Taskbar.TaskbarButtonCreatedMessage Then
            InitializeThumbButtons()
        ElseIf m.Msg = HK_MSG_ID Then
            Dim id As IntPtr = m.WParam
            Select Case (id.ToString)
                Case "100"
                    VolumeMoins()
                    TestVolume()
                    TrackBar1.Value = Volume
                    TrackBar2.Value = Volume
                    buffChaine.Clear()
                    timBuffChaine.Enabled = False
                Case "200"
                    VolumePlus()
                    TestVolume()
                    TrackBar1.Value = Volume
                    TrackBar2.Value = Volume
                    buffChaine.Clear()
                    timBuffChaine.Enabled = False
                Case "300"
                    ToggleMute()
                    TestVolume()
                    TrackBar1.Value = Volume
                    TrackBar2.Value = Volume
                    buffChaine.Clear()
                    timBuffChaine.Enabled = False
                    'Case "400"
                    '    Snapshot(SnapshotsPath & "Snapshot_" & DateTime.Now.Year & DateTime.Now.Month & DateTime.Now.Day & DateTime.Now.Hour & DateTime.Now.Minute & DateTime.Now.Second & ".png")
            End Select
        End If
        If tbm IsNot Nothing Then
            tbm.DispatchMessage(m)
        End If

        MyBase.WndProc(m)
    End Sub

    Protected Sub InitializeThumbButtons()
        If tbm Is Nothing Then
            tbm = WindowsForms.WindowsFormsExtensions.CreateThumbButtonManager(Me)
        End If

        Dim tbbSnapshot As ThumbButton = tbm.CreateThumbButton(1, Icon.FromHandle(My.Resources.camera.GetHicon), "Capturer")
        AddHandler tbbSnapshot.Clicked, AddressOf tbbSnapshot_click

        Dim tbbMute As ThumbButton = tbm.CreateThumbButton(2, Icon.FromHandle(My.Resources.speakervolume.GetHicon), "Muet")
        AddHandler tbbMute.Clicked, AddressOf tbbmute_click

        Dim tbbSwap As ThumbButton = tbm.CreateThumbButton(3, Icon.FromHandle(My.Resources.arrow_circle_double.GetHicon), "Swap")
        AddHandler tbbSwap.Clicked, AddressOf tbbSwap_click

        Dim tbbChaineMoins As ThumbButton = tbm.CreateThumbButton(4, Icon.FromHandle(My.Resources.controlskip180.GetHicon), "Chaîne -")
        AddHandler tbbChaineMoins.Clicked, AddressOf tbbChaineMoins_click

        Dim tbbChainePlus As ThumbButton = tbm.CreateThumbButton(5, Icon.FromHandle(My.Resources.controlskip.GetHicon), "Chaîne +")
        AddHandler tbbChainePlus.Clicked, AddressOf tbbChainePlus_click

        Dim tbbPlaypause As ThumbButton = tbm.CreateThumbButton(6, Icon.FromHandle(My.Resources.controlpause.GetHicon), "Pause")
        AddHandler tbbPlaypause.Clicked, AddressOf tbbPlaypause_click

        Dim tbbRecord As ThumbButton = tbm.CreateThumbButton(7, Icon.FromHandle(My.Resources.controlrecord.GetHicon), "Enregistrer")
        AddHandler tbbRecord.Clicked, AddressOf tbbRecord_click
        tbm.AddThumbButtons(tbbSnapshot, tbbMute, tbbSwap, tbbChaineMoins, tbbChainePlus, tbbPlaypause, tbbRecord)
    End Sub

    Sub tbbSnapshot_click(ByVal sender As Object, ByVal e As EventArgs)
        Snapshot(SnapshotsPath & "Snapshot_" & DateTime.Now.Year & DateTime.Now.Month & DateTime.Now.Day & DateTime.Now.Hour & DateTime.Now.Minute & DateTime.Now.Second & ".png")
    End Sub

    Sub tbbmute_click(ByVal sender As Object, ByVal e As EventArgs)
        ToggleMute()
        TrackBar1.Value = Volume
        TrackBar2.Value = Volume
        TestVolume()
    End Sub

    Sub tbbSwap_click(ByVal sender As Object, ByVal e As EventArgs)
        If ToggleChannel() Then
            Watch()
            MajChainesToolStrip()
        End If
    End Sub

    Sub tbbChaineMoins_click(ByVal sender As Object, ByVal e As EventArgs)
        ChooseChannelMoins()
        MajChainesToolStrip()
    End Sub

    Sub tbbChainePlus_click(ByVal sender As Object, ByVal e As EventArgs)
        ChooseChannelPlus()
        MajChainesToolStrip()
    End Sub

    Sub tbbPlaypause_click(ByVal sender As Object, ByVal e As EventArgs)
        If isPlaying Then
            Pause()
            PlayPauseToolStripMenuItem.Image = My.Resources.control
        Else
            Play()
            PlayPauseToolStripMenuItem.Image = My.Resources.controlpause
        End If
        VisuRateToolStripMenuItem.Text = Speed
    End Sub

    Sub tbbRecord_click(ByVal sender As Object, ByVal e As EventArgs)
        If isPlaying Then
            FileName = VideosPath & "Chaine" & DateTime.Now.Year & "_" & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" & DateTime.Now.Hour & "H" & DateTime.Now.Minute & DateTime.Now.Second & ".ts"
            RecordNow = Not (RecordNow)
            If RecordNow Then
                RecordToolStripMenuItem.Image = My.Resources.controlpauserecord
                EnregistrerToolStripMenuItem.Text = "Arreter"
                EnregistrerToolStripMenuItem1.Text = "Arreter"
            Else
                RecordToolStripMenuItem.Image = My.Resources.controlrecord
                EnregistrerToolStripMenuItem.Text = "Enregistrer"
                EnregistrerToolStripMenuItem1.Text = "Enregistrer"
            End If
        End If

    End Sub

#End Region

#Region "Menus"

    Private Sub SwapChannelToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SwapChannelToolStripMenuItem.Click
        If ToggleChannel() Then
            Watch()
            MajChainesToolStrip()
        End If
    End Sub

    Private Sub MenuPlaylistItem_click(ByVal sender As Object, ByVal e As EventArgs)
        currentPlaylist = CLng(DirectCast(sender, ToolStripMenuItem).Tag)
        If UpdateMenuChannel() Then
            If ChooseChannelByOrdering(1) Then
                Watch()
                For Each testListeChaine As Object In ListeDeChainesToolStripMenuItem.DropDown.Items
                    If TypeOf (testListeChaine) Is ToolStripMenuItem Then
                        If Not DirectCast(testListeChaine, ToolStripMenuItem).Tag.Equals(currentPlaylist) Then
                            DirectCast(testListeChaine, ToolStripMenuItem).Checked = False
                        Else
                            DirectCast(testListeChaine, ToolStripMenuItem).Checked = True
                        End If
                    End If
                Next

                For Each testListeChaine As Object In ListeDeChainesToolStripMenuItem1.DropDown.Items
                    If TypeOf (testListeChaine) Is ToolStripMenuItem Then
                        If Not DirectCast(testListeChaine, ToolStripMenuItem).Tag.Equals(currentPlaylist) Then
                            DirectCast(testListeChaine, ToolStripMenuItem).Checked = False
                        Else
                            DirectCast(testListeChaine, ToolStripMenuItem).Checked = True
                        End If
                    End If
                Next
                For i As Integer = 1 To ChainesToolStripMenuItem.DropDown.Items.Count - 1
                    DirectCast(ChainesToolStripMenuItem.DropDown.Items(0), ToolStripMenuItem).Checked = False
                    DirectCast(ChainesToolStripMenuItem1.DropDown.Items(0), ToolStripMenuItem).Checked = False
                Next
                DirectCast(ChainesToolStripMenuItem.DropDown.Items(0), ToolStripMenuItem).Checked = True
                DirectCast(ChainesToolStripMenuItem1.DropDown.Items(0), ToolStripMenuItem).Checked = True
            End If

        End If
    End Sub

    Private Sub MenuPlaylistEnregistrementItem_click(ByVal sender As Object, ByVal e As EventArgs)
        UpdateMenuEnregistrement()
        For Each testListeChaine As Object In ListeDeChainesToolStripMenuItem.DropDown.Items
            If TypeOf (testListeChaine) Is ToolStripMenuItem Then
                If Not DirectCast(testListeChaine, ToolStripMenuItem).Tag.Equals(999999999999999999) Then
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = False
                Else
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = True
                End If
            End If
        Next

        For Each testListeChaine As Object In ListeDeChainesToolStripMenuItem1.DropDown.Items
            If TypeOf (testListeChaine) Is ToolStripMenuItem Then
                If Not DirectCast(testListeChaine, ToolStripMenuItem).Tag.Equals(999999999999999999) Then
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = False
                Else
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = True
                End If
            End If
        Next


    End Sub

    Private Function UpdateMenuChannel() As Boolean
        PlayRecord = False
        'recuperation de la playlist active et de ses chaines
        ChainesToolStripMenuItem.DropDown.Items.Clear()
        ChainesToolStripMenuItem1.DropDown.Items.Clear()
        Dim ListChaines() As Channels
        If currentPlaylist > 0 Then
            ListChaines = LoadChannelsFromPlaylist(currentPlaylist)
            'creation du menu des chaines
            For t As Integer = 0 To ListChaines.Count - 1
                Dim mniChaine As New ToolStripMenuItem
                mniChaine.Text = ListChaines(t).Name
                mniChaine.Tag = ListChaines(t).Id
                mniChaine.ForeColor = Color.DarkOrange
                AddHandler mniChaine.Click, AddressOf MenuChaineItem_Click
                ChainesToolStripMenuItem.DropDown.Items.Add(mniChaine)
                mniChaine = Nothing

                Dim mniChaine2 As New ToolStripMenuItem
                mniChaine2.Text = ListChaines(t).Name
                mniChaine2.Tag = ListChaines(t).Id
                mniChaine2.ForeColor = Color.DarkOrange
                AddHandler mniChaine2.Click, AddressOf MenuChaineItem_Click
                ChainesToolStripMenuItem1.DropDown.Items.Add(mniChaine2)
                mniChaine2 = Nothing

            Next
            Return True
        Else
            Return False
        End If
    End Function

    Private Sub UpdateMenuEnregistrement()
        ChainesToolStripMenuItem.DropDown.Items.Clear()
        ChainesToolStripMenuItem1.DropDown.Items.Clear()
        Dim enreg(-1) As String
        Dim cpt As Integer = -1
        If Directory.EnumerateFiles(VideosPath).Count > 0 Then
            ReDim enreg(Directory.EnumerateFiles(VideosPath).Count)
            For Each rec As String In Directory.EnumerateFiles(VideosPath)
                If rec.Substring(rec.LastIndexOf(".") + 1).Equals("ts") Then
                    cpt += 1
                    enreg(cpt) = rec
                End If
            Next
            ReDim Preserve enreg(cpt)
        End If


        If enreg.Count > 0 Then
            For Each rec As String In enreg
                Dim mniEnregistrement As New ToolStripMenuItem
                mniEnregistrement.Text = rec.Substring(rec.LastIndexOf("\") + 1)
                mniEnregistrement.Tag = New Uri(rec).AbsoluteUri
                mniEnregistrement.ForeColor = Color.DarkOrange
                AddHandler mniEnregistrement.Click, AddressOf MenuEnregistrement_Click
                ChainesToolStripMenuItem.DropDown.Items.Add(mniEnregistrement)
                mniEnregistrement = Nothing
                Dim mniEnregistrement2 As New ToolStripMenuItem
                mniEnregistrement2.Text = rec.Substring(rec.LastIndexOf("\") + 1)
                mniEnregistrement2.Tag = New Uri(rec).AbsoluteUri
                mniEnregistrement2.ForeColor = Color.DarkOrange
                AddHandler mniEnregistrement2.Click, AddressOf MenuEnregistrement_Click
                ChainesToolStripMenuItem1.DropDown.Items.Add(mniEnregistrement2)
                mniEnregistrement2 = Nothing
            Next
            PlayRecord = True
        Else
            Dim mniEnregistrement As New ToolStripMenuItem
            mniEnregistrement.Text = _PasdEnregistrement
            mniEnregistrement.ForeColor = Color.DarkOrange
            ChainesToolStripMenuItem.DropDown.Items.Add(mniEnregistrement)
            mniEnregistrement = Nothing


            Dim mniEnregistrement2 As New ToolStripMenuItem
            mniEnregistrement2.Text = _PasdEnregistrement
            mniEnregistrement2.ForeColor = Color.DarkOrange
            ChainesToolStripMenuItem1.DropDown.Items.Add(mniEnregistrement2)
            mniEnregistrement2 = Nothing
            PlayRecord = False

        End If


    End Sub

    Private Sub UpdateMenuPlaylist()
        Dim playlist() As ListPlayList = LoadPlaylist()
        ListeDeChainesToolStripMenuItem.DropDown.Items.Clear()
        ListeDeChainesToolStripMenuItem1.DropDown.Items.Clear()
        Dim mniEnregistrement As New ToolStripMenuItem
        mniEnregistrement.Text = _Enregistrement
        mniEnregistrement.Tag = 999999999999999999
        mniEnregistrement.ForeColor = Color.DarkOrange

        AddHandler mniEnregistrement.Click, AddressOf MenuPlaylistEnregistrementItem_click
        ListeDeChainesToolStripMenuItem.DropDown.Items.Add(mniEnregistrement)

        Dim mniEnregistrement2 As New ToolStripMenuItem
        mniEnregistrement2.Text = _Enregistrement
        mniEnregistrement2.Tag = 999999999999999999
        mniEnregistrement2.ForeColor = Color.DarkOrange
        AddHandler mniEnregistrement2.Click, AddressOf MenuPlaylistEnregistrementItem_click
        ListeDeChainesToolStripMenuItem1.DropDown.Items.Add(mniEnregistrement2)


        If playlist.Count > 0 Then

            Dim tss As New ToolStripSeparator
            ListeDeChainesToolStripMenuItem.DropDown.Items.Add(tss)

            Dim tss2 As New ToolStripSeparator
            ListeDeChainesToolStripMenuItem1.DropDown.Items.Add(tss2)
            For t As Integer = 0 To playlist.Count - 1
                Dim mniPlaylist As New ToolStripMenuItem
                mniPlaylist.Text = playlist(t).Name
                mniPlaylist.Tag = playlist(t).Id
                mniPlaylist.ForeColor = Color.DarkOrange
                AddHandler mniPlaylist.Click, AddressOf MenuPlaylistItem_click
                ListeDeChainesToolStripMenuItem.DropDown.Items.Add(mniPlaylist)
                mniPlaylist = Nothing

                Dim mniPlaylist2 As New ToolStripMenuItem
                mniPlaylist2.Text = playlist(t).Name
                mniPlaylist2.Tag = playlist(t).Id
                mniPlaylist2.ForeColor = Color.DarkOrange
                AddHandler mniPlaylist2.Click, AddressOf MenuPlaylistItem_click
                ListeDeChainesToolStripMenuItem1.DropDown.Items.Add(mniPlaylist2)
                mniPlaylist2 = Nothing


            Next
        End If
        currentPlaylist = ActivePlaylist
        For Each testListeChaine As Object In ListeDeChainesToolStripMenuItem.DropDown.Items
            If TypeOf (testListeChaine) Is ToolStripMenuItem Then
                If Not DirectCast(testListeChaine, ToolStripMenuItem).Tag.Equals(currentPlaylist) Then
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = False
                Else
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = True
                End If
            End If
        Next

        For Each testListeChaine As Object In ListeDeChainesToolStripMenuItem1.DropDown.Items
            If TypeOf (testListeChaine) Is ToolStripMenuItem Then
                If Not DirectCast(testListeChaine, ToolStripMenuItem).Tag.Equals(currentPlaylist) Then
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = False
                Else
                    DirectCast(testListeChaine, ToolStripMenuItem).Checked = True
                End If
            End If
        Next

    End Sub

    Private Sub MenuChaineItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        If ChooseChanneById(CInt(DirectCast(sender, ToolStripMenuItem).Tag)) Then
            For Each testToolstripmenuitem As ToolStripMenuItem In ChainesToolStripMenuItem.DropDown.Items
                If Not testToolstripmenuitem.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                    testToolstripmenuitem.Checked = False
                Else
                    testToolstripmenuitem.Checked = True
                End If
            Next

            For Each testToolstripmenuitem As ToolStripMenuItem In ChainesToolStripMenuItem1.DropDown.Items
                If Not testToolstripmenuitem.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                    testToolstripmenuitem.Checked = False
                Else
                    testToolstripmenuitem.Checked = True
                End If
            Next
            Watch()
        End If
    End Sub

    Private Sub MenuEnregistrement_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim file As String = DirectCast(sender, ToolStripMenuItem).Tag.ToString
        Watch(file)
    End Sub

    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        Volume = TrackBar1.Value
        TrackBar2.Value = Volume
        TestVolume()
    End Sub

    Private Sub TrackBar2_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar2.Scroll
        Volume = TrackBar2.Value
        TrackBar1.Value = Volume
        TestVolume()
    End Sub

    Private Sub trackbar2_mouseup(ByVal sender As Object, ByVal e As MouseEventArgs) Handles TrackBar2.MouseUp
        ContextMenuStripPnlVideo.Hide()
        'TrackBar1.Value = Volume
        'TestVolume()
    End Sub

    Private Sub QuitterToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QuitterToolStripMenuItem.Click, QuitterToolStripMenuItem1.Click
        Me.Close()
    End Sub

    Private Sub GestionDesListeEtDesChainesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GestionDesListeEtDesChainesToolStripMenuItem.Click, GestionDesListeEtDesChainesToolStripMenuItem1.Click
        Dim frmplaylistandchannelmanagement As New PlaylistAndChannelManagement
        Translator.Translate(frmplaylistandchannelmanagement)
        frmplaylistandchannelmanagement.ShowDialog()
        UpdateMenuPlaylist()
        If UpdateMenuChannel() Then
            If ChooseChannelByOrdering(1) Then
                Watch()
            End If

        End If
    End Sub

    Private Sub AutoToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AutoToolStripMenuItem1.Click, AutoToolStripMenuItem3.Click
        For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem.DropDownItems
            If Not TSMI.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                TSMI.Checked = False
            Else
                TSMI.Checked = True
            End If
        Next
        For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem1.DropDownItems
            If Not TSMI.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                TSMI.Checked = False
            Else
                TSMI.Checked = True
            End If
        Next

        AspectRatio = AspectRatioMode.Default
    End Sub

    Private Sub ToolStripMenuItem3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem3.Click, ToolStripMenuItem6.Click
        For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem.DropDownItems
            If Not TSMI.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                TSMI.Checked = False
            Else
                TSMI.Checked = True
            End If
        Next
        For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem1.DropDownItems
            If Not TSMI.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                TSMI.Checked = False
            Else
                TSMI.Checked = True
            End If
        Next

        AspectRatio = AspectRatioMode.Mode2
    End Sub

    Private Sub ToolStripMenuItem4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem4.Click, ToolStripMenuItem7.Click
        For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem.DropDownItems
            If Not TSMI.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                TSMI.Checked = False
            Else
                TSMI.Checked = True
            End If
        Next
        For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem1.DropDownItems
            If Not TSMI.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                TSMI.Checked = False
            Else
                TSMI.Checked = True
            End If
        Next
        AspectRatio = AspectRatioMode.Mode3
    End Sub

    Private Sub DeinterlaceStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AutoToolStripMenuItem.Click, OnToolStripMenuItem.Click, OffToolStripMenuItem.Click, _
        AutoToolStripMenuItem2.Click, OnToolStripMenuItem1.Click, OffToolStripMenuItem1.Click
        For Each tsmi As ToolStripMenuItem In DesenterlacementToolStripMenuItem.DropDownItems
            If Not tsmi.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next
        For Each tsmi As ToolStripMenuItem In DesentrelacementToolStripMenuItem.DropDownItems
            If Not tsmi.Text.Equals(DirectCast(sender, ToolStripMenuItem).Text) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next

        desentrelace = DirectCast(sender, ToolStripMenuItem).Text
    End Sub

    Private Sub DeinterlaceModeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DiscardToolStripMenuItem.Click, BlendToolStripMenuItem.Click, BobToolStripMenuItem.Click, LinearToolStripMenuItem.Click, XToolStripMenuItem.Click, YadiffToolStripMenuItem.Click, Yadif2xToolStripMenuItem.Click _
        , DiscardToolStripMenuItem1.Click, BlendToolStripMenuItem1.Click, BobToolStripMenuItem1.Click, LinearToolStripMenuItem1.Click, XToolStripMenuItem1.Click, YadiffToolStripMenuItem1.Click, Yadif2XToolStripMenuItem1.Click
        For Each tsmi As ToolStripMenuItem In ModeDeDésentrelacementToolStripMenuItem.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If

        Next
        For Each tsmi As ToolStripMenuItem In ModeDeDésentrelacementToolStripMenuItem1.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next
        ModeDesentrelace = DirectCast(CInt(DirectCast(sender, ToolStripMenuItem).Tag), DeinterlaceMode)
    End Sub

    Private Sub VolumeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolumeToolStripMenuItem.Click, VolumeToolStripMenuItem2.Click
        VolumePlus()
        TrackBar1.Value = Volume
        TrackBar2.Value = Volume
        TestVolume()
    End Sub

    Private Sub VolumeToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolumeToolStripMenuItem1.Click, VolumeToolStripMenuItem3.Click
        VolumeMoins()
        TrackBar1.Value = Volume
        TrackBar2.Value = Volume
        TestVolume()
    End Sub

    Private Sub AProposToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AProposToolStripMenuItem.Click
        Dim frmapropos As New Apropos
        Translator.Translate(frmapropos)
        frmapropos.ShowDialog()

        'Apropos.ShowDialog()
    End Sub

    Private Sub RéglageDeLimageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RéglageDeLimageToolStripMenuItem.Click, RéglageDeLimageToolStripMenuItem1.Click
        Dim frmReglage As New ReglageImage
        Translator.Translate(frmReglage)
        frmReglage.ShowDialog()
    End Sub

    Private Sub EnregistrerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EnregistrerToolStripMenuItem.Click, EnregistrerToolStripMenuItem1.Click, RecordToolStripMenuItem.Click
        If isPlaying Then
            FileName = VideosPath & "Chaine" & DateTime.Now.Year & "_" & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" & DateTime.Now.Hour & "H" & DateTime.Now.Minute & DateTime.Now.Second & ".ts"
            RecordNow = Not (RecordNow)
            If RecordNow Then
                RecordToolStripMenuItem.Image = My.Resources.controlpauserecord
                EnregistrerToolStripMenuItem.Text = _Arreter
                EnregistrerToolStripMenuItem1.Text = _Arreter
            Else
                RecordToolStripMenuItem.Image = My.Resources.controlrecord
                EnregistrerToolStripMenuItem.Text = _enregistrer
                EnregistrerToolStripMenuItem1.Text = _enregistrer
            End If
        End If

    End Sub

    Private Sub GérerLesEnregistrementsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GérerLesEnregistrementsToolStripMenuItem.Click, GérerLesEnregistrementsToolStripMenuItem1.Click
        'GestionEnregistrement.ShowDialog()
    End Sub

    Private Sub MettreEnAvantplanToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MettreEnAvantplanToolStripMenuItem.Click, MettreEnAvantplanToolStripMenuItem1.Click
        toggleTopMost()
    End Sub

    Private Sub OuvrirLeDossierToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OuvrirLeDossierToolStripMenuItem.Click, OuvrirLeDossierToolStripMenuItem1.Click
        Process.Start("explorer.exe", "/e," & VideosPath)
    End Sub

    Private Sub OuvrirLeDossierDeCaptureToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OuvrirLeDossierDeCaptureToolStripMenuItem.Click, OuvrirLeDossierDeCaptureToolStripMenuItem1.Click
        Process.Start("explorer.exe", "/e," & SnapshotsPath)
    End Sub

    Private Sub ListeDesCommandesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListeDesCommandesToolStripMenuItem.Click
        Process.Start(AppPath & "commandes.pdf")
    End Sub

    Private Sub RedimensionnementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BilinéaireRapideToolStripMenuItem.Click _
    , BilinéaireToolStripMenuItem.Click, BicubiqueToolStripMenuItem.Click, ExpérimentalToolStripMenuItem.Click, PlusProcheVoisinToolStripMenuItem.Click _
    , ZoneToolStripMenuItem.Click, BicubiquebilinéaireToolStripMenuItem.Click, GaussienToolStripMenuItem.Click, SincRToolStripMenuItem.Click _
    , LanczosToolStripMenuItem.Click, CourbeBicubiqueToolStripMenuItem.Click, BilinéaireRapideToolStripMenuItem1.Click, BilinéaireToolStripMenuItem1.Click _
    , BicubiqueToolStripMenuItem.Click, ExpérimentalToolStripMenuItem1.Click, PlusProcheVoisinToolStripMenuItem1.Click, ZoneToolStripMenuItem1.Click, BicubiquebilinéaireToolStripMenuItem1.Click _
    , GaussienToolStripMenuItem1.Click, SincRToolStripMenuItem1.Click, LanczosToolStripMenuItem1.Click, CourbeBicubiqueToolStripMenuItem1.Click _
    , DéfautToolStripMenuItem.Click, DéfautToolStripMenuItem1.Click

        SWScaleMode = DirectCast(CInt(DirectCast(sender, ToolStripMenuItem).Tag), Redimensionnement)

        For Each tsmi As ToolStripMenuItem In RetaillageToolStripMenuItem.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If

        Next
        For Each tsmi As ToolStripMenuItem In ModeRetaillageToolStripMenuItem.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If

        Next

    End Sub

    Private Sub DécodageHardwareToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DécodageHardwareToolStripMenuItem2.Click, DécodageHardwareToolStripMenuItem.Click
        HardwareDecoding = Not HardwareDecoding
        DécodageHardwareToolStripMenuItem2.Checked = HardwareDecoding
        DécodageHardwareToolStripMenuItem.Checked = HardwareDecoding
    End Sub

    Private Sub Postproc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem8.Click, ToolStripMenuItem9.Click _
        , ToolStripMenuItem10.Click, ToolStripMenuItem11.Click, ToolStripMenuItem12.Click, ToolStripMenuItem13.Click, ToolStripMenuItem14.Click _
        , DésactivéToolStripMenuItem.Click, ToolStripMenuItem36.Click, ToolStripMenuItem37.Click, ToolStripMenuItem38.Click, ToolStripMenuItem39.Click _
        , ToolStripMenuItem40.Click, ToolStripMenuItem41.Click
        PostProcessus = CInt(DirectCast(sender, ToolStripMenuItem).Tag)
        For Each tsmi As ToolStripMenuItem In PostProcToolStripMenuItem.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next
        For Each tsmi As ToolStripMenuItem In PostProcToolStripMenuItem1.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next

    End Sub

    Private Sub Nettete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem35.Click, ToolStripMenuItem15.Click, ToolStripMenuItem16.Click _
        , ToolStripMenuItem17.Click, ToolStripMenuItem18.Click, ToolStripMenuItem19.Click, ToolStripMenuItem20.Click, ToolStripMenuItem21.Click, ToolStripMenuItem22.Click, ToolStripMenuItem23.Click _
        , ToolStripMenuItem24.Click, ToolStripMenuItem25.Click, ToolStripMenuItem26.Click, ToolStripMenuItem27.Click, ToolStripMenuItem28.Click, ToolStripMenuItem29.Click, ToolStripMenuItem30.Click _
        , ToolStripMenuItem31.Click, ToolStripMenuItem32.Click, ToolStripMenuItem33.Click, ToolStripMenuItem34.Click, DésactivéToolStripMenuItem1.Click, ToolStripMenuItem42.Click _
        , ToolStripMenuItem43.Click, ToolStripMenuItem44.Click, ToolStripMenuItem45.Click, ToolStripMenuItem48.Click, ToolStripMenuItem49.Click _
        , ToolStripMenuItem50.Click, ToolStripMenuItem51.Click, ToolStripMenuItem52.Click, ToolStripMenuItem53.Click, ToolStripMenuItem54.Click, ToolStripMenuItem55.Click, ToolStripMenuItem56.Click _
        , ToolStripMenuItem57.Click, ToolStripMenuItem58.Click, ToolStripMenuItem59.Click, ToolStripMenuItem60.Click, ToolStripMenuItem62.Click, ToolStripMenuItem61.Click, ToolStripMenuItem63.Click
        SharpenSigma = (DirectCast(sender, ToolStripMenuItem).Tag.ToString)

        For Each tsmi As ToolStripMenuItem In FiltreNettetéToolStripMenuItem.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next
        For Each tsmi As ToolStripMenuItem In FiltreNettetéToolStripMenuItem1.DropDownItems
            If Not tsmi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next

    End Sub

    Private Sub SkipLoopFilterStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AucunToolStripMenuItem.Click, NonrefToolStripMenuItem.Click, BidirToolStripMenuItem.Click, NonKeyToolStripMenuItem.Click, TousToolStripMenuItem.Click, _
    AucunToolStripMenuItem1.Click, NonrefToolStripMenuItem1.Click, BidirToolStripMenuItem1.Click, NonkeyToolStripMenuItem1.Click, TousToolStripMenuItem1.Click
        SautFilterBoucle = DirectCast(CInt(DirectCast(sender, ToolStripMenuItem).Tag), SkipLoopFilter)
        For Each tmsi As ToolStripMenuItem In SauterLesFiltresDeBouclesToolStripMenuItem.DropDownItems
            If Not tmsi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tmsi.Checked = False
            Else
                tmsi.Checked = True
            End If
        Next
        For Each tmsi As ToolStripMenuItem In SauterLesFiltresDeBoucleToolStripMenuItem1.DropDownItems
            If Not tmsi.Tag.Equals(DirectCast(sender, ToolStripMenuItem).Tag) Then
                tmsi.Checked = False
            Else
                tmsi.Checked = True
            End If
        Next

    End Sub

    Private Sub NormaliserLeSonToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NormaliserLeSonToolStripMenuItem.Click, NormaliserLeVolumeToolStripMenuItem.Click
        NormalisationVolume = Not NormalisationVolume
        NormaliserLeSonToolStripMenuItem.Checked = NormalisationVolume
        NormaliserLeVolumeToolStripMenuItem.Checked = NormalisationVolume
    End Sub

    Private Sub AutoExtinctionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AutoExtinctionToolStripMenuItem.Click
        Dim frmautoextinction As New AutoExtinction
        Translator.Translate(frmautoextinction)
        frmautoextinction.ShowDialog()
        'AutoExtinction.ShowDialog()
    End Sub

    Private Sub PALFILMToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PALFILMToolStripMenuItem.Click, PALFilmToolStripMenuItem1.Click
        ToggleCompensatePalSpeedUp()
        PALFILMToolStripMenuItem.Checked = CompensationPalSpeedUp
        PALFilmToolStripMenuItem1.Checked = CompensationPalSpeedUp
    End Sub

    Private Sub MajChainesToolStrip()
        For Each testToolstripmenuitem As ToolStripMenuItem In ChainesToolStripMenuItem.DropDown.Items
            If Not CInt(testToolstripmenuitem.Tag).Equals(ID) Then
                testToolstripmenuitem.Checked = False
            Else
                testToolstripmenuitem.Checked = True
            End If
        Next

        For Each testToolstripmenuitem As ToolStripMenuItem In ChainesToolStripMenuItem1.DropDown.Items
            If Not CInt(testToolstripmenuitem.Tag).Equals(ID) Then
                testToolstripmenuitem.Checked = False
            Else
                testToolstripmenuitem.Checked = True
            End If
        Next

    End Sub

#End Region

#Region "barre de commande"

    Private Sub ColorToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColorToolStripMenuItem.Click
        ReglageImage.ShowDialog()
    End Sub

    Private Sub SnapshotToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SnapshotToolStripMenuItem.Click
        Snapshot(SnapshotsPath & "Snapshot_" & DateTime.Now.Year & DateTime.Now.Month & DateTime.Now.Day & DateTime.Now.Hour & DateTime.Now.Minute & DateTime.Now.Second & ".png")
    End Sub

    Private Sub VolumeDownToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolumeDownToolStripMenuItem.Click
        VolumeMoins()
        TrackBar1.Value = Volume
        TrackBar2.Value = Volume
        TestVolume()
    End Sub

    Private Sub volumeUpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles volumeUpToolStripMenuItem.Click
        VolumePlus()
        TrackBar1.Value = Volume
        TrackBar2.Value = Volume
        TestVolume()

    End Sub

    Private Sub MuteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MuteToolStripMenuItem.Click, MuetToolStripMenuItem.Click, MuetToolStripMenuItem1.Click
        ToggleMute()
        TrackBar1.Value = Volume
        TrackBar2.Value = Volume
        TestVolume()
    End Sub

    Private Sub ChaineMoinsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChaineMoinsToolStripMenuItem.Click
        If Not PlayRecord Then
            ChooseChannelMoins()
            MajChainesToolStrip()
        End If
    End Sub

    Private Sub ChainePlusToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChainePlusToolStripMenuItem.Click
        If Not PlayRecord Then
            ChooseChannelPlus()
            MajChainesToolStrip()
        End If
    End Sub

    Private Sub DecelerateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DecelerateToolStripMenuItem.Click
        Decelerate()
        VisuRateToolStripMenuItem.Text = Speed.PadRight(5)
    End Sub

    Private Sub PlayPauseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlayPauseToolStripMenuItem.Click
        If isPlaying Then
            Pause()
            PlayPauseToolStripMenuItem.Image = My.Resources.control
        Else
            Play()
            PlayPauseToolStripMenuItem.Image = My.Resources.controlpause
        End If
        VisuRateToolStripMenuItem.Text = Speed.PadRight(5)
    End Sub

    'Private Sub RecordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RecordToolStripMenuItem.Click
    '    If isPlaying Then
    '        FileName = VideosPath & "Chaine" & DateTime.Now.Year & "_" & DateTime.Now.Month & "_" & DateTime.Now.Day & "_" & DateTime.Now.Hour & "H" & DateTime.Now.Minute & DateTime.Now.Second & ".ts"
    '        RecordNow = Not (RecordNow)
    '        If RecordNow Then
    '            RecordToolStripMenuItem.Image = My.Resources.controlpauserecord
    '        Else
    '            RecordToolStripMenuItem.Image = My.Resources.controlrecord
    '        End If
    '    End If

    'End Sub

    Private Sub ToolStripMenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem2.Click
        Accelerate()
        VisuRateToolStripMenuItem.Text = Speed.PadRight(5)
    End Sub


#End Region

#Region "Traduction"
    Private _Muet As String = "MUET"
    Public Property Muet As String
        Get
            Return _Muet
        End Get
        Set(ByVal value As String)
            _Muet = value
            Cpb1.StringMuet = _Muet
        End Set
    End Property
    Private _Aller As String = "Aller à : "
    Public Property AllerA As String
        Get
            Return _Aller
        End Get
        Set(ByVal value As String)
            _Aller = value
        End Set
    End Property
    Private _Arreter As String = "Arrêter"
    Public Property Arreter As String
        Get
            Return _Arreter
        End Get
        Set(ByVal value As String)
            _Arreter = value
        End Set
    End Property
    Private _enregistrer As String = "Enregistrer"
    Public Property Enregistrer As String
        Get
            Return _enregistrer
        End Get
        Set(ByVal value As String)
            _enregistrer = value
        End Set
    End Property
    Private _PasdEnregistrement As String = "Pas d'enregistrements"
    Public Property PasdEnregistrement As String
        Get
            Return _PasdEnregistrement
        End Get
        Set(ByVal value As String)
            _PasdEnregistrement = value
        End Set
    End Property
    Private _Enregistrement As String = "Enregistrements"
    Public Property Enregistrement As String
        Get
            Return _Enregistrement
        End Get
        Set(ByVal value As String)
            _Enregistrement = value
        End Set
    End Property
    Private Sub LanguagesMenu_DropDownItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles LanguagesMenu.DropDownItemClicked
        If Translator.Translation.Exists(e.ClickedItem.Text) Then
            Try
                Translator.Translation.CurrentLanguage = e.ClickedItem.Text
                Translator.Translate(Me)
                Language = e.ClickedItem.Text
                UpdateMenuPlaylist()
            Catch ex As Exception
            End Try
        End If
    End Sub

    Private Sub LoadLanguagesMenu()
        Language = My.Settings.Langage
        Try
            Translator.Translation.CurrentLanguage = Language
            Translator.Translate(Me)
            FillLanguagesMenu()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

    Private Sub FillLanguagesMenu()
        For Each lang As KeyValuePair(Of String, TranslationClasses) In Translator.Translation
            Dim found As Boolean = False
            For Each item As Object In LanguagesMenu.DropDownItems
                If TypeOf item Is ToolStripMenuItem AndAlso DirectCast(item, ToolStripMenuItem).Text = lang.Key Then
                    found = True
                End If
            Next
            If found = False Then
                Dim mnilangue As New ToolStripMenuItem
                mnilangue.Text = lang.Key
                mnilangue.ForeColor = Color.DarkOrange
                LanguagesMenu.DropDownItems.Add(mnilangue)
                'LanguagesMenu.DropDownItems.Add(lang.Key)
            End If
        Next
    End Sub
#End Region

#Region "Mainform"
    Private Sub TimerStop_InfoClose() Handles TimerStop.InfoClose
        Me.Close()
    End Sub

    Private Sub TimerStop_Terminate() Handles TimerStop.InfoStop
        SaveSetting()
    End Sub
    Public Sub SaveSetting()
        'releaseHotkey()
        With My.Settings
            .Langage = Language
            .HasBorder = hasBorder
            .IsFullscreen = isFullscreen
            .Topmost = isTopmost
            If isFullscreen Then
                ToggleFullscreen()
            End If
            .EtatFenetre = Me.WindowState
            .Size = Me.Size
            .Location = Me.Location
            If IsCreated Then
                .IdChaine = ID
                .Volume = Volume
                .AR = DirectCast(AspectRatio, Integer)
                .Deinterlace = desentrelace
                .DeinterlaceMode = DirectCast(ModeDesentrelace, Integer)
                .PostProc = PostProcessus
                .Hw_Decoding = HardwareDecoding
                .Sharpen = SharpenSigma
                .SwScale = SWScaleMode
                .NormVol = NormalisationVolume
                .Skiploopfilter = SautFilterBoucle
            End If
            .Save()
        End With

    End Sub
    Public Sub New()

        ' Cet appel est requis par le concepteur.
        InitializeComponent()
        ToolStripManager.Renderer = New MyToolStripRenderer
        ' Ajoutez une initialisation quelconque après l'appel InitializeComponent().

    End Sub
    Private Sub Mainform_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        releaseHotkey()
        SaveSetting()
        If IsCreated Then
            DisposeVlcPlayer()
        End If
    End Sub


    Private Sub Mainform_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Application.EnableVisualStyles()

        LoadLanguagesMenu()

        Dim fv As FileVersionInfo
        fv = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location)
        Me.Text = "ZViewTV.NET v" & fv.FileVersion

        AddHandler System.AppDomain.CurrentDomain.UnhandledException, AddressOf OnUnhandledException
        AddHandler Application.ThreadException, AddressOf OnUnhandledGUIException
        AddHandler player.ChannelChanged, AddressOf channelchanged_event
        AddHandler player.ChannelChanging, AddressOf channelchanging_event
        initHotKey()
        initOSD()

        TrackBar1.Alignment = ToolStripItemAlignment.Right
        TrackBar1.Padding = New Padding(0, 0, 0, 0)
        TrackBar1.AutoSize = False
        mnsMainform.Items.Add(TrackBar1)

        TrackBar2.Alignment = ToolStripItemAlignment.Left
        TrackBar2.Padding = New Padding(0, 0, 0, 0)
        TrackBar2.AutoSize = False
        TrackBar2.Width = ContextMenuStripPnlVideo.Width - 1
        TrackBar2.BackColor = Color.Gray

        ContextMenuStripPnlVideo.Items.Insert(0, TrackBar2)

        For Each ctrl As Control In Me.Controls
            ctrl.TabStop = False
            If ctrl.HasChildren Then
                For t As Integer = 0 To ctrl.Controls.Count - 1
                    ctrl.Controls(t).TabStop = False
                Next
            End If
        Next
        With My.Settings
            Me.WindowState = .EtatFenetre
            Me.Location = .Location
            Me.Size = .Size
            If Not (.HasBorder) Then ToggleBorder()
            If .IsFullscreen Then ToggleFullscreen()
            isTopmost = .Topmost
            Me.TopMost = isTopmost
            MettreEnAvantplanToolStripMenuItem.Checked = isTopmost
        End With
        PathDefinition()
        timBuffChaine.Interval = 2500
        initDatabase(My.Settings.IdChaine)
        InitVlcPlayer(pnlVideo.Handle)
        Volume = My.Settings.Volume
        TrackBar1.Value = Volume
        TrackBar2.Value = Volume

        UpdateMenuPlaylist()
        If UpdateMenuChannel() Then
            If Environment.GetCommandLineArgs.Length > 1 Then
                SilentRecording = True
                Select Case Environment.GetCommandLineArgs(1).Split(CChar("-"))(0)
                    Case "/RecById"
                        ChooseChannelByOrdering(Integer.Parse(Environment.GetCommandLineArgs(1).Split(CChar("-"))(1)))
                    Case "/RecByZGId"
                        ChooseChannelByZgId(Environment.GetCommandLineArgs(2))
                    Case Else
                End Select
                RecordDuration = CInt(Environment.GetCommandLineArgs(2).Split(CChar("-"))(1))
                FileName = Environment.GetCommandLineArgs(3).Split(CChar("-"))(1)
                Me.WindowState = FormWindowState.Minimized
                Me.ShowInTaskbar = False
                NotifyIcon1.Visible = True
            Else
                If My.Settings.IdChaine > 0 Then
                    ChooseChanneById(My.Settings.IdChaine)
                    For Each testToolstripmenuitem As ToolStripMenuItem In ChainesToolStripMenuItem.DropDown.Items
                        If CInt(testToolstripmenuitem.Tag) = My.Settings.IdChaine Then
                            testToolstripmenuitem.Checked = True
                        End If
                    Next
                    For Each testToolstripmenuitem As ToolStripMenuItem In ChainesToolStripMenuItem1.DropDown.Items
                        If CInt(testToolstripmenuitem.Tag) = My.Settings.IdChaine Then
                            testToolstripmenuitem.Checked = True
                        End If
                    Next

                Else
                    ChooseChannelByOrdering(1)
                    DirectCast(ChainesToolStripMenuItem.DropDown.Items(0), ToolStripMenuItem).Checked = True
                End If
            End If
            With My.Settings
                InitMedia(.Deinterlace, .DeinterlaceMode, .PostProc, .Hw_Decoding, .Sharpen, .SwScale, .NormVol, .Skiploopfilter)
                Watch()
            End With
            AspectRatio = DirectCast(My.Settings.AR, AspectRatioMode)
            Dim titi As String = GetEnumDescription(AspectRatio)
            For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem.DropDownItems

                If Not TSMI.Text.Equals(GetEnumDescription(AspectRatio)) Then
                    TSMI.Checked = False
                Else
                    TSMI.Checked = True
                End If
            Next
            For Each TSMI As ToolStripMenuItem In AspectRatioToolStripMenuItem1.DropDownItems
                If Not TSMI.Text.Equals(GetEnumDescription(AspectRatio)) Then
                    TSMI.Checked = False
                Else
                    TSMI.Checked = True
                End If
            Next
            For Each tsmi As ToolStripMenuItem In ModeDeDésentrelacementToolStripMenuItem.DropDownItems
                If Not CInt(tsmi.Tag) = (DirectCast(ModeDesentrelace, Integer)) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next
            For Each tsmi As ToolStripMenuItem In ModeDeDésentrelacementToolStripMenuItem1.DropDownItems
                If Not CInt(tsmi.Tag) = (DirectCast(ModeDesentrelace, Integer)) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next
            For Each tsmi As ToolStripMenuItem In DesenterlacementToolStripMenuItem.DropDownItems
                If Not tsmi.Text.Equals(desentrelace) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next
            For Each tsmi As ToolStripMenuItem In DesentrelacementToolStripMenuItem.DropDownItems
                If Not tsmi.Text.Equals(desentrelace) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next

            For Each tsmi As ToolStripMenuItem In PostProcToolStripMenuItem.DropDownItems
                If Not tsmi.Tag.Equals(PostProcessus.ToString) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If

            Next

            For Each tsmi As ToolStripMenuItem In PostProcToolStripMenuItem1.DropDownItems
                If Not tsmi.Tag.Equals(PostProcessus.ToString) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If

            Next

            For Each tsmi As ToolStripMenuItem In FiltreNettetéToolStripMenuItem.DropDownItems
                If Not tsmi.Tag.Equals(SharpenSigma) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next

            For Each tsmi As ToolStripMenuItem In FiltreNettetéToolStripMenuItem1.DropDownItems
                If Not tsmi.Tag.Equals(SharpenSigma) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next
            For Each tsmi As ToolStripMenuItem In SauterLesFiltresDeBouclesToolStripMenuItem.DropDownItems
                If Not CInt(tsmi.Tag) = DirectCast(SautFilterBoucle, Integer) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next
            For Each tsmi As ToolStripMenuItem In SauterLesFiltresDeBoucleToolStripMenuItem1.DropDownItems
                If Not CInt(tsmi.Tag) = DirectCast(SautFilterBoucle, Integer) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next

            For Each tsmi As ToolStripMenuItem In RetaillageToolStripMenuItem.DropDownItems
                If Not CInt(tsmi.Tag) = DirectCast(SWScaleMode, Integer) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next

            For Each tsmi As ToolStripMenuItem In ModeRetaillageToolStripMenuItem.DropDownItems
                If Not CInt(tsmi.Tag) = DirectCast(SWScaleMode, Integer) Then
                    tsmi.Checked = False
                Else
                    tsmi.Checked = True
                End If
            Next

            DécodageHardwareToolStripMenuItem2.Checked = HardwareDecoding
            DécodageHardwareToolStripMenuItem.Checked = HardwareDecoding
            NormaliserLeSonToolStripMenuItem.Checked = NormalisationVolume
            NormaliserLeVolumeToolStripMenuItem.Checked = NormalisationVolume
        End If
        'test.Show()
        TestVolume()
        DisplayOSD = False

    End Sub
    Sub channelchanged_event(ByVal strchaine As String)
        ' TODO
        'Factorisation du code de mise à jour des menus "listes" et "chaines"
        ConstruireMenuSoustitreEtAudio()
        ConstruireMenuTeletext()
        AfficheOSDChaine(strchaine)
        TimerSoustitresAudio.Enabled = True
        ChaineActuelle = strchaine
        If HasVideo Then
            AfficheOSDChaine(strchaine)
            IsRadio = False
        Else
            If HasAudio Then
                AfficheOSDRadio(strchaine)
                IsRadio = True
            Else
                IsRadio = False
            End If
        End If
    End Sub
    Sub channelchanging_event()
        TimerSoustitresAudio.Enabled = False
        CacheOSD()
    End Sub

    Sub ToggleBorder()
        If Not isFullscreen Then
            'test.ListBox1.Items.Insert(0, "Passage dans toggleborder")
            'Me.SuspendLayout()
            Dim hauteumenu As Integer = mnsMainform.Height
            If Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None Then
                mnsMainform.Visible = True
                Me.BackColor = Color.White
                pnlVideo.BorderStyle = BorderStyle.None
                Me.Padding = New Padding(0)
                pnlVideo.Location = New Point(0, hauteumenu)
                'HoteOSDChaine.Location = New Point(0, hauteumenu)
                pnlVideo.Height = pnlVideo.Height - hauteumenu
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
                hasBorder = True
                Me.Cursor = Cursors.Default

            Else
                Me.BackColor = Color.LightGray
                pnlVideo.BackColor = Color.White
                mnsMainform.Visible = False
                pnlVideo.Location = New Point(0, 0)
                'HoteOSDChaine.Location = New Point(0, 0)
                pnlVideo.BorderStyle = BorderStyle.FixedSingle
                Me.Padding = New Padding(5)
                pnlVideo.Height = pnlVideo.Height + hauteumenu
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
                hasBorder = False
            End If
            'Me.ResumeLayout()
        End If
        If IsRadio Then
            AfficheOSDRadio(ChaineActuelle)
        End If
    End Sub

    Private Sub ToggleFullscreen()

        Dim hauteumenu As Integer = mnsMainform.Height
        Static EtatFenetre As FormWindowState = FormWindowState.Normal

        If isFullscreen Then
            'fullscreen vers fenetre normale
            If hasBorder Then
                pnlVideo.Location = New Point(0, hauteumenu)
                HoteOSDChaine.Location = New Point(0, hauteumenu)
                pnlVideo.Height = pnlVideo.Height - hauteumenu
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.Sizable
                Me.WindowState = EtatFenetre
                Me.TopMost = isTopmost
                'fullscreen vers sans fenetre 
            Else
                Me.BackColor = Color.LightGray
                pnlVideo.BackColor = Color.White
                mnsMainform.Visible = False
                pnlVideo.Location = New Point(0, 0)
                'HoteOSDChaine.Location = New Point(0, 0)
                pnlVideo.BorderStyle = BorderStyle.FixedSingle
                Me.Padding = New Padding(5)
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
                Me.WindowState = EtatFenetre
                Me.TopMost = isTopmost
            End If
            isFullscreen = False
        Else
            'Non fullscreen et fenetre normale vers fullscreen
            If hasBorder Then
                EtatFenetre = Me.WindowState
                Me.TopMost = True
                If Me.WindowState = FormWindowState.Maximized AndAlso osversion >= 6 Then
                    Me.WindowState = FormWindowState.Normal
                End If
                pnlVideo.Location = New Point(0, 0)
                'HoteOSDChaine.Location = New Point(0, 0)
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
                Me.WindowState = FormWindowState.Maximized
                pnlVideo.Height = pnlVideo.Height + hauteumenu
                'non fullscreen et sans fenetre vers fullscreen
            Else
                EtatFenetre = Me.WindowState
                Me.TopMost = True
                Me.Padding = New Padding(0)

                If Me.WindowState = FormWindowState.Maximized AndAlso osversion >= 6 Then
                    Me.WindowState = FormWindowState.Normal
                End If
                pnlVideo.BorderStyle = BorderStyle.None
                pnlVideo.Location = New Point(0, 0)
                Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
                Me.WindowState = FormWindowState.Maximized
            End If
            isFullscreen = True
        End If
        If IsRadio Then
            AfficheOSDRadio(ChaineActuelle)
        End If
    End Sub

    Private Sub toggleTopMost()
        isTopmost = Not (isTopmost)
        Me.TopMost = isTopmost
        MettreEnAvantplanToolStripMenuItem.Checked = isTopmost
        MettreEnAvantplanToolStripMenuItem1.Checked = isTopmost
    End Sub

    Sub TestVolume()
        Static iszero As Boolean
        If Volume > 0 AndAlso iszero Then
            MuteToolStripMenuItem.Image = My.Resources.speakervolume
            iszero = False
        ElseIf Volume = 0 AndAlso (Not (iszero)) Then
            MuteToolStripMenuItem.Image = My.Resources.speakervolumecontrolmute
            iszero = True
        End If
        If Not DisplayOSD Then
            AfficheOSDVolume()
        End If
    End Sub

#End Region

#Region "OSD"

    Public Sub initOSD()
        hoteOSDRadio.Parent = Me
        hoteOSDRadio.Top = pnlVideo.Bottom - HoteOSDVolume.Height - 250
        hoteOSDRadio.Left = pnlVideo.Left + 200
        hoteOSDRadio.Enabled = False

        HoteOSDVolume.Parent = Me
        HoteOSDVolume.Top = pnlVideo.Bottom - HoteOSDVolume.Height
        HoteOSDVolume.Left = pnlVideo.Left
        HoteOSDVolume.Enabled = False

        HoteOSDChaine.Parent = Me
        HoteOSDChaine.Top = pnlVideo.Top
        HoteOSDChaine.Left = pnlVideo.Left
        HoteOSDChaine.Width = pnlVideo.Width
        HoteOSDChaine.Enabled = False
    End Sub

    Public Sub AfficheOSDVolume()

        Dim rectVideo As RectangleF = Videolocation()
        If rectVideo.Height > 0 AndAlso rectVideo.Width > 0 Then

            Dim baseTaille As Double = Math.Min(Math.Max(CInt(Math.Ceiling(rectVideo.Height / 8.0)), 40), 150)
            Static memoBasetaille As Double = 0
            If memoBasetaille <> baseTaille Then
                HoteOSDVolume.Top = CInt(pnlVideo.Top + rectVideo.Y + rectVideo.Height - (baseTaille * 1.5))
                HoteOSDVolume.Left = CInt(rectVideo.X + baseTaille * 0.5)
                memoBasetaille = baseTaille
                HoteOSDVolume.Width = CInt(baseTaille)
            End If
            HoteOSDVolume.Height = CInt(baseTaille)
            Cpb1.Percentage = Volume
            Cpb1.Scale(baseTaille)

            HoteOSDVolume.BringToFront()
            TimerOSDVolume.Enabled = True
            TimerOSDVolume.Start()
        End If

    End Sub

    Private Sub TimerOSDVolume_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerOSDVolume.Tick
        HoteOSDVolume.SendToBack()
        HoteOSDVolume.Height = 0
        TimerOSDVolume.Stop()
        TimerOSDVolume.Enabled = False
    End Sub
    Public Sub AfficheOSDRadio(ByVal NomRadio As String)
        If AffichageRadio1 IsNot Nothing Then
            If AffichageRadio1.IsArrangeValid Then
                hoteOSDRadio.Height = 156
                hoteOSDRadio.Top = pnlVideo.Top + CInt((pnlVideo.Height - hoteOSDRadio.Height) / 2)
                hoteOSDRadio.Width = AffichageRadio1.Affiche(pnlVideo.Width, NomRadio)
                hoteOSDRadio.Left = CInt((pnlVideo.Width - hoteOSDRadio.Width) / 2)
                hoteOSDRadio.BringToFront()
            End If
        End If
    End Sub
    Public Sub AfficheOSDChaine(Optional ByVal texte As String = "")
        If texte = "" Then texte = ChaineActuelle
        If AffichageTexte1 IsNot Nothing Then
            If AffichageTexte1.IsArrangeValid Then
                Dim rectVideo As RectangleF = Videolocation()
                If rectVideo.Height > 0 AndAlso rectVideo.Width > 0 Then
                    Dim baseTaille As Double = Math.Min(Math.Max(CInt(Math.Ceiling(pnlVideo.Height / 25.0)), 20), 120)
                    HoteOSDChaine.Top = CInt(pnlVideo.Top + rectVideo.Top + baseTaille)
                    HoteOSDChaine.Left = CInt(rectVideo.Left + baseTaille)
                    HoteOSDChaine.Height = CInt(baseTaille)
                    HoteOSDChaine.Width = AffichageTexte1.Affiche(CInt(baseTaille), pnlVideo.Width - CInt(baseTaille * 2), texte)
                    HoteOSDChaine.BringToFront()
                    TimerOSDChaine.Enabled = True
                    TimerOSDChaine.Start()
                End If
            End If
        End If
    End Sub

    Private Sub TimerOSDChaine_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerOSDChaine.Tick
        HoteOSDChaine.SendToBack()
        HoteOSDChaine.Height = 0
        TimerOSDChaine.Stop()
        TimerOSDChaine.Enabled = False
        'buffChaine.Clear()
    End Sub

    Public Sub CacheOSD()
        HoteOSDChaine.Height = 0
        HoteOSDVolume.Height = 0
        hoteOSDRadio.Height = 0
        hoteOSDRadio.SendToBack()
        HoteOSDChaine.SendToBack()
        TimerOSDChaine.Stop()
        TimerOSDChaine.Enabled = False
        HoteOSDVolume.SendToBack()
        TimerOSDVolume.Stop()
        TimerOSDVolume.Enabled = False
    End Sub

    Private Function Videolocation() As RectangleF
        Dim hautgauche As New Point(0, 0)
        Dim basdroit As New Size(0, 0)
        If Largeur > 0 AndAlso Hauteur > 0 Then 'evite les division par zero lorsque le player n'est en lecture


            Dim ratiolargeur As Double = pnlVideo.Width / Largeur
            Dim ratiohauteur As Double = pnlVideo.Height / Hauteur

            hautgauche.X = CInt(Math.Max(0, (pnlVideo.Width - (Largeur * ratiohauteur)) / 2))
            hautgauche.Y = CInt(Math.Max(0, (pnlVideo.Height - (Hauteur * ratiolargeur)) / 2))

            basdroit.Width = CInt(Math.Min(pnlVideo.Width, Largeur * ratiohauteur))
            basdroit.Height = CInt(Math.Min(pnlVideo.Height, Hauteur * ratiolargeur))
        End If
        Return New RectangleF(hautgauche, basdroit)
    End Function
    Private Sub Mainform_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        CacheOSD()
        If IsRadio Then
            AfficheOSDRadio(ChaineActuelle)
        End If
    End Sub

#End Region

#Region "Sous-Titres et Pistes Audio"
    Private Sub TimerSoustitresAudio_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerSoustitresAudio.Tick
        If IsCreated Then
            ConstruireMenuSoustitreEtAudio()
            ConstruireMenuTeletext()
        End If
    End Sub
    Sub ConstruireMenuTeletext()
        For i As Integer = 0 To TeletextToolStripMenuItem.DropDown.Items.Count - 1
            TeletextToolStripMenuItem.DropDown.Items.RemoveAt(0)
        Next
        For i As Integer = 0 To TeletextToolStripMenuItem1.DropDown.Items.Count - 1
            TeletextToolStripMenuItem1.DropDown.Items.RemoveAt(0)
        Next

        Dim listeTeletext As New Dictionary(Of Integer, String)
        listeTeletext = ListTeletext
        TeletextToolStripMenuItem.Enabled = True
        If listeTeletext.Count > 0 Then
            For Each teletext As KeyValuePair(Of Integer, String) In listeTeletext
                Dim menuitemTeletext As New ToolStripMenuItem(teletext.Value)
                menuitemTeletext.Tag = teletext.Key
                menuitemTeletext.ForeColor = Color.DarkOrange
                AddHandler menuitemTeletext.Click, AddressOf menuitemTeletext_click
                TeletextToolStripMenuItem.DropDown.Items.Add(menuitemTeletext)

                Dim menuitemTeletext1 As New ToolStripMenuItem(teletext.Value)
                menuitemTeletext1.Tag = teletext.Key
                menuitemTeletext1.ForeColor = Color.DarkOrange
                AddHandler menuitemTeletext1.Click, AddressOf menuitemTeletext_click
                TeletextToolStripMenuItem1.DropDown.Items.Add(menuitemTeletext1)

                Dim teletextactuel As Integer = SousTitre
                If teletext.Key = teletextactuel Then
                    CType(TeletextToolStripMenuItem.DropDown.Items(TeletextToolStripMenuItem.DropDown.Items.Count - 1), ToolStripMenuItem).Checked = True
                    CType(TeletextToolStripMenuItem1.DropDown.Items(TeletextToolStripMenuItem1.DropDown.Items.Count - 1), ToolStripMenuItem).Checked = True
                End If

            Next
        Else
            TeletextToolStripMenuItem.Enabled = False
        End If


    End Sub
    Sub ConstruireMenuSoustitreEtAudio()
        'construction du menu soustitre
        For i As Integer = 0 To SousTitresToolStripMenuItem.DropDown.Items.Count - 1
            SousTitresToolStripMenuItem.DropDown.Items.RemoveAt(0)
        Next
        For i As Integer = 0 To SousTitresToolStripMenuItem1.DropDown.Items.Count - 1
            SousTitresToolStripMenuItem1.DropDown.Items.RemoveAt(0)
        Next

        Dim listSt As New Dictionary(Of Integer, String)
        listSt = ListeSousTitre

        If listSt.Count > 0 AndAlso listSt.ElementAt(0).Value <> "Pas de sous-titre" Then
            SousTitresToolStripMenuItem.Enabled = True
            SousTitresToolStripMenuItem1.Enabled = True
            Dim stactuel As Integer = SousTitre
            For Each st As KeyValuePair(Of Integer, String) In listSt
                Dim menuitemst As New ToolStripMenuItem(st.Value)
                menuitemst.Tag = st.Key
                menuitemst.ForeColor = Color.DarkOrange
                AddHandler menuitemst.Click, AddressOf MenuItemSoustitre_Click
                SousTitresToolStripMenuItem.DropDown.Items.Add(menuitemst)
                Dim menuitemst1 As New ToolStripMenuItem(st.Value)
                menuitemst1.Tag = st.Key
                menuitemst1.ForeColor = Color.DarkOrange
                AddHandler menuitemst1.Click, AddressOf MenuItemSoustitre_Click
                SousTitresToolStripMenuItem1.DropDown.Items.Add(menuitemst1)
                If st.Key = stactuel Then
                    CType(SousTitresToolStripMenuItem.DropDown.Items(SousTitresToolStripMenuItem.DropDown.Items.Count - 1), ToolStripMenuItem).Checked = True
                    CType(SousTitresToolStripMenuItem1.DropDown.Items(SousTitresToolStripMenuItem1.DropDown.Items.Count - 1), ToolStripMenuItem).Checked = True
                End If

            Next

        Else
            SousTitresToolStripMenuItem.Enabled = False
            SousTitresToolStripMenuItem1.Enabled = False
        End If

        'construction du menu piste audio
        For i As Integer = 0 To PistesToolStripMenuItem.DropDown.Items.Count - 1
            PistesToolStripMenuItem.DropDown.Items.RemoveAt(0)
        Next
        For i As Integer = 0 To PistesToolStripMenuItem1.DropDown.Items.Count - 1
            PistesToolStripMenuItem1.DropDown.Items.RemoveAt(0)
        Next

        Dim listAudio As New Dictionary(Of Integer, String)
        listAudio = ListeTrackAudio

        If listAudio.Count > 0 AndAlso listAudio.ElementAt(0).Value <> "Pas d'audio !!!" Then
            PistesToolStripMenuItem.Enabled = True
            PistesToolStripMenuItem1.Enabled = True
            Dim actuelaudio As Integer = TrackAudio

            For Each audio As KeyValuePair(Of Integer, String) In listAudio
                Dim menuitemAudio As New ToolStripMenuItem(audio.Value)
                menuitemAudio.Tag = audio.Key
                menuitemAudio.ForeColor = Color.DarkOrange
                AddHandler menuitemAudio.Click, AddressOf MenuItemAudio_Click
                PistesToolStripMenuItem.DropDown.Items.Add(menuitemAudio)

                Dim menuitemAudio1 As New ToolStripMenuItem(audio.Value)
                menuitemAudio1.Tag = audio.Key
                menuitemAudio1.ForeColor = Color.DarkOrange
                AddHandler menuitemAudio1.Click, AddressOf MenuItemAudio_Click
                PistesToolStripMenuItem1.DropDown.Items.Add(menuitemAudio1)
                If audio.Key = actuelaudio Then
                    CType(PistesToolStripMenuItem.DropDown.Items(PistesToolStripMenuItem.DropDown.Items.Count - 1), ToolStripMenuItem).Checked = True
                    CType(PistesToolStripMenuItem1.DropDown.Items(PistesToolStripMenuItem1.DropDown.Items.Count - 1), ToolStripMenuItem).Checked = True
                End If
            Next

        Else
            PistesToolStripMenuItem.Enabled = False
            PistesToolStripMenuItem1.Enabled = False
        End If

    End Sub

    Sub MenuItemSoustitre_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim st As Integer = CInt(CType(sender, ToolStripMenuItem).Tag)
        SousTitre = st

        For Each tsmi As ToolStripMenuItem In SousTitresToolStripMenuItem.DropDownItems
            If Not CInt(tsmi.Tag) = st Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next

        For Each tsmi As ToolStripMenuItem In SousTitresToolStripMenuItem1.DropDownItems
            If Not CInt(tsmi.Tag) = st Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next

        For Each tsmi As ToolStripMenuItem In TeletextToolStripMenuItem.DropDownItems
            tsmi.Checked = False
        Next
        For Each tsmi As ToolStripMenuItem In TeletextToolStripMenuItem1.DropDownItems
            tsmi.Checked = False
        Next


    End Sub
    Sub menuitemTeletext_click(ByVal sender As Object, ByVal e As EventArgs)
        Dim teletext As Integer = CInt(CType(sender, ToolStripMenuItem).Tag)
        SousTitre = teletext
        ToggleTeletext()

        For Each tsmi As ToolStripMenuItem In TeletextToolStripMenuItem.DropDownItems
            If Not CInt(tsmi.Tag) = teletext Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next

        For Each tsmi As ToolStripMenuItem In SousTitresToolStripMenuItem.DropDownItems
            tsmi.Checked = False
        Next
        For Each tsmi As ToolStripMenuItem In SousTitresToolStripMenuItem1.DropDownItems
            tsmi.Checked = False
        Next

    End Sub

    Sub MenuItemAudio_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim audio As Integer = CInt(CType(sender, ToolStripMenuItem).Tag)
        TrackAudio = audio
        For Each tsmi As ToolStripMenuItem In PistesToolStripMenuItem.DropDownItems
            If Not CInt(tsmi.Tag) = audio Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next
        For Each tsmi As ToolStripMenuItem In PistesToolStripMenuItem1.DropDownItems
            If Not CInt(tsmi.Tag) = audio Then
                tsmi.Checked = False
            Else
                tsmi.Checked = True
            End If
        Next
    End Sub

#End Region

#Region "Erreur"

    Private Sub OnUnhandledException(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs)
        releaseHotkey()
        Dim e As Exception = DirectCast(args.ExceptionObject, Exception)
        errorstring = e.Message & Environment.NewLine & e.StackTrace
        erreur.ShowDialog()
    End Sub

    Private Sub OnUnhandledGUIException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
        releaseHotkey()
        errorstring = e.Exception.Message & Environment.NewLine & e.Exception.StackTrace
        erreur.ShowDialog()
    End Sub

#End Region

#Region "test"

    '    Private Sub pnlVideo_Desc(ByVal m As System.Windows.Forms.Message) Handles pnlVideo.Desc

    '        Dim messag As String
    '        Select Case m.Msg
    '            Case WM.WM_MOUSEACTIVATE
    '                messag = "WM_MOUSEACTIVATE"
    '            Case WM.WM_PARENTNOTIFY
    '                messag = "WM_PARENTNOTIFY"
    '            Case WM.WM_SETCURSOR
    '                messag = "WM_SETCURSOR"
    '            Case WM.WM_LBUTTONDOWN
    '                messag = "WM_LBUTTONDOWN"
    '            Case WM.WM_RBUTTONDOWN
    '                messag = "WM_RBUTTONDOWN"
    '            Case WM.WM_MBUTTONDOWN
    '                messag = "WM_MBUTTONDOWN"
    '            Case Else
    '                messag = m.Msg.ToString
    '        End Select
    '        If Not m.Msg = 20 Then
    '            test.ListBox1.Items.Insert(0, "Message:" & messag & " LParam:" & m.LParam.ToString & " wParam:" & m.WParam.ToString)

    '        End If

    '    End Sub

    '    Enum WM
    '        WM_ACTIVATE = &H6
    '        WM_ACTIVATEAPP = &H1C
    '        WM_AFXFIRST = &H360
    '        WM_AFXLAST = &H37F
    '        WM_APP = &H8000
    '        WM_ASKCBFORMATNAME = &H30C
    '        WM_CANCELJOURNAL = &H4B
    '        WM_CANCELMODE = &H1F
    '        WM_CAPTURECHANGED = &H215
    '        WM_CHANGECBCHAIN = &H30D
    '        WM_CHAR = &H102
    '        WM_CHARTOITEM = &H2F
    '        WM_CHILDACTIVATE = &H22
    '        WM_CLEAR = &H303
    '        WM_CLOSE = &H10
    '        WM_COMMAND = &H111
    '        WM_COMPACTING = &H41
    '        WM_COMPAREITEM = &H39
    '        WM_CONTEXTMENU = &H7B
    '        WM_COPY = &H301
    '        WM_COPYDATA = &H4A
    '        WM_CREATE = &H1
    '        WM_CTLCOLORBTN = &H135
    '        WM_CTLCOLORDLG = &H136
    '        WM_CTLCOLOREDIT = &H133
    '        WM_CTLCOLORLISTBOX = &H134
    '        WM_CTLCOLORMSGBOX = &H132
    '        WM_CTLCOLORSCROLLBAR = &H137
    '        WM_CTLCOLORSTATIC = &H138
    '        WM_CUT = &H300
    '        WM_DEADCHAR = &H103
    '        WM_DELETEITEM = &H2D
    '        WM_DESTROY = &H2
    '        WM_DESTROYCLIPBOARD = &H307
    '        WM_DEVICECHANGE = &H219
    '        WM_DEVMODECHANGE = &H1B
    '        WM_DISPLAYCHANGE = &H7E
    '        WM_DRAWCLIPBOARD = &H308
    '        WM_DRAWITEM = &H2B
    '        WM_DROPFILES = &H233
    '        WM_ENABLE = &HA
    '        WM_ENDSESSION = &H16
    '        WM_ENTERIDLE = &H121
    '        WM_ENTERMENULOOP = &H211
    '        WM_ENTERSIZEMOVE = &H231
    '        WM_ERASEBKGND = &H14
    '        WM_EXITMENULOOP = &H212
    '        WM_EXITSIZEMOVE = &H232
    '        WM_FONTCHANGE = &H1D
    '        WM_GETDLGCODE = &H87
    '        WM_GETFONT = &H31
    '        WM_GETHOTKEY = &H33
    '        WM_GETICON = &H7F
    '        WM_GETMINMAXINFO = &H24
    '        WM_GETOBJECT = &H3D
    '        WM_GETTEXT = &HD
    '        WM_GETTEXTLENGTH = &HE
    '        WM_HANDHELDFIRST = &H358
    '        WM_HANDHELDLAST = &H35F
    '        WM_HELP = &H53
    '        WM_HOTKEY = &H312
    '        WM_HSCROLL = &H114
    '        WM_HSCROLLCLIPBOARD = &H30E
    '        WM_ICONERASEBKGND = &H27
    '        WM_IME_CHAR = &H286
    '        WM_IME_COMPOSITION = &H10F
    '        WM_IME_COMPOSITIONFULL = &H284
    '        WM_IME_CONTROL = &H283
    '        WM_IME_ENDCOMPOSITION = &H10E
    '        WM_IME_KEYDOWN = &H290
    '        WM_IME_KEYLAST = &H10F
    '        WM_IME_KEYUP = &H291
    '        WM_IME_NOTIFY = &H282
    '        WM_IME_REQUEST = &H288
    '        WM_IME_SELECT = &H285
    '        WM_IME_SETCONTEXT = &H281
    '        WM_IME_STARTCOMPOSITION = &H10D
    '        WM_INITDIALOG = &H110
    '        WM_INITMENU = &H116
    '        WM_INITMENUPOPUP = &H117
    '        WM_INPUTLANGCHANGE = &H51
    '        WM_INPUTLANGCHANGEREQUEST = &H50
    '        WM_KEYDOWN = &H100
    '        WM_KEYFIRST = &H100
    '        WM_KEYLAST = &H108
    '        WM_KEYUP = &H101
    '        WM_KILLFOCUS = &H8
    '        WM_LBUTTONDBLCLK = &H203
    '        WM_LBUTTONDOWN = &H201
    '        WM_LBUTTONUP = &H202
    '        WM_MBUTTONDBLCLK = &H209
    '        WM_MBUTTONDOWN = &H207
    '        WM_MBUTTONUP = &H208
    '        WM_MDIACTIVATE = &H222
    '        WM_MDICASCADE = &H227
    '        WM_MDICREATE = &H220
    '        WM_MDIDESTROY = &H221
    '        WM_MDIGETACTIVE = &H229
    '        WM_MDIICONARRANGE = &H228
    '        WM_MDIMAXIMIZE = &H225
    '        WM_MDINEXT = &H224
    '        WM_MDIREFRESHMENU = &H234
    '        WM_MDIRESTORE = &H223
    '        WM_MDISETMENU = &H230
    '        WM_MDITILE = &H226
    '        WM_MEASUREITEM = &H2C
    '        WM_MENUCHAR = &H120
    '        WM_MENUCOMMAND = &H126
    '        WM_MENUDRAG = &H123
    '        WM_MENUGETOBJECT = &H124
    '        WM_MENURBUTTONUP = &H122
    '        WM_MENUSELECT = &H11F
    '        WM_MOUSEACTIVATE = &H21
    '        WM_MOUSEHOVER = &H2A1
    '        WM_MOUSELAST = &H20A
    '        WM_MOUSELEAVE = &H2A3
    '        WM_MOUSEMOVE = &H200
    '        WM_MOUSEFIRST = &H200
    '        WM_MOUSEWHEEL = &H20A
    '        WM_MOVE = &H3
    '        WM_MOVING = &H216
    '        WM_NCACTIVATE = &H86
    '        WM_NCCALCSIZE = &H83
    '        WM_NCCREATE = &H81
    '        WM_NCDESTROY = &H82
    '        WM_NCHITTEST = &H84
    '        WM_NCLBUTTONDBLCLK = &HA3
    '        WM_NCLBUTTONDOWN = &HA1
    '        WM_NCLBUTTONUP = &HA2
    '        WM_NCMBUTTONDBLCLK = &HA9
    '        WM_NCMBUTTONDOWN = &HA7
    '        WM_NCMBUTTONUP = &HA8
    '        WM_NCMOUSEHOVER = &H2A0
    '        WM_NCMOUSEMOVE = &HA0
    '        WM_NCPAINT = &H85
    '        WM_NCRBUTTONDBLCLK = &HA6
    '        WM_NCRBUTTONDOWN = &HA4
    '        WM_NCRBUTTONUP = &HA5
    '        WM_NCXBUTTONDOWN = &HAB
    '        WM_NCXBUTTONUP = &HAC
    '        WM_NCXBUTTONDBLCLK = &HAD
    '        WM_NEXTDLGCTL = &H28
    '        WM_NEXTMENU = &H213
    '        WM_NOTIFY = &H4E
    '        WM_NOTIFYFORMAT = &H55
    '        WM_NULL = &H0
    '        WM_PAINT = &HF
    '        WM_PAINTCLIPBOARD = &H309
    '        WM_PAINTICON = &H26
    '        WM_PALETTECHANGED = &H311
    '        WM_PALETTEISCHANGING = &H310
    '        WM_PARENTNOTIFY = &H210
    '        WM_PASTE = &H302
    '        WM_PENWINFIRST = &H380
    '        WM_PENWINLAST = &H38F
    '        WM_POWER = &H48
    '        WM_PRINT = &H317
    '        WM_PRINTCLIENT = &H318
    '        WM_QUERYDRAGICON = &H37
    '        WM_QUERYENDSESSION = &H11
    '        WM_QUERYNEWPALETTE = &H30F
    '        WM_QUERYOPEN = &H13
    '        WM_QUEUESYNC = &H23
    '        WM_QUIT = &H12
    '        WM_RBUTTONDBLCLK = &H206
    '        WM_RBUTTONDOWN = &H204
    '        WM_RBUTTONUP = &H205
    '        WM_RENDERALLFORMATS = &H306
    '        WM_RENDERFORMAT = &H305
    '        WM_SETCURSOR = &H20
    '        WM_SETFOCUS = &H7
    '        WM_SETFONT = &H30
    '        WM_SETHOTKEY = &H32
    '        WM_SETICON = &H80
    '        WM_SETREDRAW = &HB
    '        WM_SETTEXT = &HC
    '        WM_SETTINGCHANGE = &H1A
    '        WM_SHOWWINDOW = &H18
    '        WM_SIZE = &H5
    '        WM_SIZECLIPBOARD = &H30B
    '        WM_SIZING = &H214
    '        WM_SPOOLERSTATUS = &H2A
    '        WM_STYLECHANGED = &H7D
    '        WM_STYLECHANGING = &H7C
    '        WM_SYNCPAINT = &H88
    '        WM_SYSCHAR = &H106
    '        WM_SYSCOLORCHANGE = &H15
    '        WM_SYSCOMMAND = &H112
    '        WM_SYSDEADCHAR = &H107
    '        WM_SYSKEYDOWN = &H104
    '        WM_SYSKEYUP = &H105
    '        WM_TCARD = &H52
    '        WM_TIMECHANGE = &H1E
    '        WM_TIMER = &H113
    '        WM_UNDO = &H304
    '        WM_UNINITMENUPOPUP = &H125
    '        WM_USER = &H400
    '        WM_USERCHANGED = &H54
    '        WM_VKEYTOITEM = &H2E
    '        WM_VSCROLL = &H115
    '        WM_VSCROLLCLIPBOARD = &H30A
    '        WM_WINDOWPOSCHANGED = &H47
    '        WM_WINDOWPOSCHANGING = &H46
    '        WM_WININICHANGE = &H1A
    '        WM_XBUTTONDOWN = &H20B
    '        WM_XBUTTONUP = &H20C
    '        WM_XBUTTONDBLCLK = &H20D
    '    End Enum

#End Region

End Class

